home *** CD-ROM | disk | FTP | other *** search
/ Apple Developer Connection Student Program / ADC Tools Sampler CD Disk 3 1999.iso / Metrowerks CodeWarrior / Java Support / Java_Source / Java2 / src / javax / swing / JScrollBar.java < prev    next >
Encoding:
Java Source  |  1999-05-28  |  24.8 KB  |  836 lines  |  [TEXT/CWIE]

  1. /*
  2.  * @(#)JScrollBar.java    1.55 98/08/28
  3.  *
  4.  * Copyright 1997, 1998 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  *
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14.  
  15. package javax.swing;
  16.  
  17. import java.io.Serializable;
  18. import java.awt.Component;
  19. import java.awt.Adjustable;
  20. import java.awt.Dimension;
  21. import java.awt.event.AdjustmentListener;
  22. import java.awt.event.AdjustmentEvent;
  23. import java.awt.Graphics;
  24.  
  25. import javax.swing.event.*;
  26. import javax.swing.plaf.*;
  27. import javax.accessibility.*;
  28.  
  29. import java.io.ObjectOutputStream;
  30. import java.io.ObjectInputStream;
  31. import java.io.IOException;
  32.  
  33.  
  34.  
  35. /**
  36.  * An implementation of a scrollbar. The user positions the knob in the
  37.  * scrollbar to determine the contents of the viewing area. The
  38.  * program typically adjusts the display so that the end of the
  39.  * scrollbar represents the end of the displayable contents, or 100%
  40.  * of the contents. The start of the scrollbar is the beginning of the 
  41.  * displayable contents, or 0%. The postion of the knob within
  42.  * those bounds then translates to the corresponding percentage of
  43.  * the displayable contents.
  44.  * <p>
  45.  * Typically, as the position of the knob in the scrollbar changes
  46.  * a corresponding change is made to the position of the JViewPort on
  47.  * the underlying view, changing the contents of the JViewPort.
  48.  * <p>
  49.  * <strong>Warning:</strong>
  50.  * Serialized objects of this class will not be compatible with
  51.  * future Swing releases.  The current serialization support is appropriate
  52.  * for short term storage or RMI between applications running the same
  53.  * version of Swing.  A future release of Swing will provide support for
  54.  * long term persistence.
  55.  *
  56.  * @see JScrollPane
  57.  * @beaninfo
  58.  *      attribute: isContainer false
  59.  *    description: A component that helps determine the visible content range of an area.
  60.  *
  61.  * @version 1.55 08/28/98
  62.  * @author David Kloba
  63.  */
  64. public class JScrollBar extends JComponent implements Adjustable, Accessible
  65. {
  66.     /**
  67.      * @see #getUIClassID
  68.      * @see #readObject
  69.      */
  70.     private static final String uiClassID = "ScrollBarUI";
  71.  
  72.     /**
  73.      * All changes from the model are treated as though the user moved
  74.      * the scrollbar knob.  
  75.      */
  76.     private ChangeListener fwdAdjustmentEvents = new ModelListener();
  77.  
  78.  
  79.     /**
  80.      * The model that represents the scrollbar's minimum, maximum, extent
  81.      * (aka "visibleAmount") and current value.
  82.      * @see #setModel
  83.      */
  84.     protected BoundedRangeModel model;
  85.  
  86.  
  87.     /**
  88.      * @see #setOrientation
  89.      */
  90.     protected int orientation;
  91.  
  92.  
  93.     /**
  94.      * @see #setUnitIncrement
  95.      */
  96.     protected int unitIncrement;
  97.  
  98.  
  99.     /**
  100.      * @see #setBlockIncrement
  101.      */
  102.     protected int blockIncrement;
  103.  
  104.     
  105.     private void checkOrientation(int orientation) {
  106.         switch (orientation) {
  107.         case VERTICAL:
  108.         case HORIZONTAL:
  109.             break;
  110.         default:
  111.             throw new IllegalArgumentException("orientation must be one of: VERTICAL, HORIZONTAL");
  112.         }
  113.     }
  114.  
  115.  
  116.     /**
  117.      * Creates a scrollbar with the specified orientation,
  118.      * value, extent, mimimum, and maximum.
  119.      * The "extent" is the size of the viewable area. It is also known
  120.      * as the "visible amount". 
  121.      * <p>
  122.      * Note: Use <code>setBlockIncrement</code> to set the block 
  123.      * increment to a size slightly smaller than the view's extent.
  124.      * That way, when the user jumps the knob to an adjacent position,
  125.      * one or two lines of the original contents remain in view.
  126.      * 
  127.      * @exception IllegalArgumentException if orientation is not one of VERTICAL, HORIZONTAL
  128.      * 
  129.      * @see #setOrientation
  130.      * @see #setValue
  131.      * @see #setVisibleAmount
  132.      * @see #setMinimum
  133.      * @see #setMaximum
  134.      */
  135.     public JScrollBar(int orientation, int value, int extent, int min, int max)   
  136.     {
  137.         checkOrientation(orientation);
  138.         this.unitIncrement = 1;
  139.         this.blockIncrement = (extent == 0) ? 1 : extent;
  140.         this.orientation = orientation;
  141.         this.model = new DefaultBoundedRangeModel(value, extent, min, max);
  142.         this.model.addChangeListener(fwdAdjustmentEvents);
  143.         updateUI();
  144.     }
  145.  
  146.  
  147.     /**
  148.      * Creates a scrollbar with the specified orientation
  149.      * and the following initial values:
  150.      * <pre>
  151.      * minimum = 0 
  152.      * maximum = 100 
  153.      * value = 0
  154.      * extent = 10
  155.      * </pre>
  156.      */
  157.     public JScrollBar(int orientation) {
  158.         this(orientation, 0, 10, 0, 100);
  159.     }
  160.  
  161.  
  162.     /**
  163.      * Creates a vertical scrollbar with the following initial values:
  164.      * <pre>
  165.      * minimum = 0 
  166.      * maximum = 100 
  167.      * value = 0
  168.      * extent = 10
  169.      * </pre>
  170.      */
  171.     public JScrollBar() {
  172.         this(VERTICAL);
  173.     }
  174.  
  175.  
  176.     /**
  177.      * Returns the delegate that implements the look and feel for 
  178.      * this component.
  179.      *
  180.      * @see JComponent#setUI
  181.      */
  182.     public ScrollBarUI getUI() { 
  183.         return (ScrollBarUI)ui;
  184.     }
  185.  
  186.  
  187.     /**
  188.      * Overrides <code>JComponent.updateUI</code>.
  189.      * @see JComponent#updateUI
  190.      */
  191.     public void updateUI() {
  192.         setUI((ScrollBarUI)UIManager.getUI(this));
  193.     }
  194.  
  195.  
  196.     /**
  197.      * Returns the name of the LookAndFeel class for this component.
  198.      *
  199.      * @return "ScrollBarUI"
  200.      * @see JComponent#getUIClassID
  201.      * @see UIDefaults#getUI
  202.      */
  203.     public String getUIClassID() {
  204.         return uiClassID;
  205.     }
  206.  
  207.  
  208.  
  209.     /**
  210.      * Returns the component's orientation (horizontal or vertical). 
  211.      *                     
  212.      * @return VERTICAL or HORIZONTAL
  213.      * @see #setOrientation
  214.      * @see java.awt.Adjustable#getOrientation
  215.      */
  216.     public int getOrientation() { 
  217.         return orientation; 
  218.     }
  219.  
  220.  
  221.     /**
  222.      * Set the scrollbar's orientation to either VERTICAL or
  223.      * HORIZONTAL.
  224.      * 
  225.      * @exception IllegalArgumentException if orientation is not one of VERTICAL, HORIZONTAL
  226.      * @see #getOrientation
  227.      * @beaninfo
  228.      *    preferred: true
  229.      *        bound: true
  230.      *    attribute: visualUpdate true
  231.      *  description: The scrollbar's orientation.
  232.      *         enum: VERTICAL JScrollBar.VERTICAL 
  233.      *               HORIZONTAL JScrollBar.HORIZONTAL
  234.      */
  235.     public void setOrientation(int orientation) 
  236.     { 
  237.         checkOrientation(orientation);
  238.         int oldValue = this.orientation;
  239.         this.orientation = orientation;
  240.         firePropertyChange("orientation", oldValue, orientation);
  241.  
  242.         if ((oldValue != orientation) && (accessibleContext != null)) {
  243.             accessibleContext.firePropertyChange(
  244.                     AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
  245.                     ((oldValue == VERTICAL) 
  246.                      ? AccessibleState.VERTICAL : AccessibleState.HORIZONTAL),
  247.                     ((orientation == VERTICAL) 
  248.                      ? AccessibleState.VERTICAL : AccessibleState.HORIZONTAL));
  249.         }
  250.         if (orientation != oldValue) {
  251.             revalidate();
  252.         }
  253.     }
  254.  
  255.  
  256.     /**
  257.      * Returns data model that handles the scrollbar's four
  258.      * fundamental properties: minimum, maximum, value, extent.
  259.      * 
  260.      * @see #setModel
  261.      */
  262.     public BoundedRangeModel getModel() { 
  263.         return model; 
  264.     }
  265.  
  266.  
  267.     /**
  268.      * Sets the model that handles the scrollbar's four
  269.      * fundamental properties: minimum, maximum, value, extent.
  270.      * 
  271.      * @see #getModel
  272.      * @beaninfo
  273.      *       bound: true
  274.      *       expert: true
  275.      * description: The scrollbar's BoundedRangeModel.
  276.      */
  277.     public void setModel(BoundedRangeModel newModel) {
  278.         Integer oldValue = null;
  279.         BoundedRangeModel oldModel = model;
  280.         if (model != null) {
  281.             model.removeChangeListener(fwdAdjustmentEvents);
  282.             oldValue = new Integer(model.getValue());
  283.         }
  284.         model = newModel;
  285.         if (model != null) {
  286.             model.addChangeListener(fwdAdjustmentEvents);
  287.         }
  288.  
  289.         firePropertyChange("model", oldModel, model);
  290.  
  291.         if (accessibleContext != null) {
  292.             accessibleContext.firePropertyChange(
  293.                     AccessibleContext.ACCESSIBLE_VALUE_PROPERTY,
  294.                     oldValue, new Integer(model.getValue()));        
  295.         }
  296.     }
  297.  
  298.  
  299.     /**
  300.      * Returns the amount to change the scrollbar's value by,
  301.      * given a unit up/down request.  A ScrollBarUI implementation
  302.      * typically calls this method when the user clicks on a scrollbar 
  303.      * up/down arrow and uses the result to update the scrollbar's
  304.      * value.   Subclasses my override this method to compute
  305.      * a value, e.g. the change required to scroll up or down one
  306.      * (variable height) line text or one row in a table.
  307.      * <p>
  308.      * The JScrollPane component creates scrollbars (by default) 
  309.      * that override this method and delegate to the viewports
  310.      * Scrollable view, if it has one.  The Scrollable interface
  311.      * provides a more specialized version of this method.
  312.      * 
  313.      * @param direction is -1 or 1 for up/down respectively
  314.      * @return the value of the unitIncrement property
  315.      * @see #setUnitIncrement
  316.      * @see #setValue
  317.      * @see Scrollable#getScrollableUnitIncrement
  318.      */
  319.     public int getUnitIncrement(int direction) { 
  320.         return unitIncrement; 
  321.     }
  322.  
  323.  
  324.     /**
  325.      * Sets the unitIncrement property.
  326.      * @see #getUnitIncrement
  327.      * @beaninfo
  328.      *   preferred: true
  329.      *       bound: true
  330.      * description: The scrollbar's unit increment.
  331.      */
  332.     public void setUnitIncrement(int unitIncrement) { 
  333.         int oldValue = this.unitIncrement;
  334.         this.unitIncrement = unitIncrement;
  335.         firePropertyChange("unitIncrement", oldValue, unitIncrement);
  336.     }
  337.  
  338.  
  339.     /**
  340.      * Returns the amount to change the scrollbar's value by,
  341.      * given a block (usually "page") up/down request.  A ScrollBarUI 
  342.      * implementation typically calls this method when the user clicks 
  343.      * above or below the scrollbar "knob" to change the value
  344.      * up or down by large amount.  Subclasses my override this 
  345.      * method to compute a value, e.g. the change required to scroll 
  346.      * up or down one paragraph in a text document.
  347.      * <p>
  348.      * The JScrollPane component creates scrollbars (by default) 
  349.      * that override this method and delegate to the viewports
  350.      * Scrollable view, if it has one.  The Scrollable interface
  351.      * provides a more specialized version of this method.
  352.      * 
  353.      * @param direction is -1 or 1 for up/down respectively
  354.      * @return the value of the blockIncrement property
  355.      * @see #setBlockIncrement
  356.      * @see #setValue
  357.      * @see Scrollable#getScrollableBlockIncrement
  358.      */
  359.     public int getBlockIncrement(int direction) { 
  360.         return blockIncrement; 
  361.     }
  362.  
  363.  
  364.     /**
  365.      * Sets the blockIncrement property.
  366.      * @see #getBlockIncrement()
  367.      * @beaninfo
  368.      *   preferred: true
  369.      *       bound: true
  370.      * description: The scrollbar's block increment.
  371.      */
  372.     public void setBlockIncrement(int blockIncrement) { 
  373.         int oldValue = this.blockIncrement;
  374.         this.blockIncrement = blockIncrement;
  375.         firePropertyChange("blockIncrement", oldValue, blockIncrement);
  376.     }
  377.  
  378.  
  379.     /**
  380.      * For backwards compatibility with java.awt.Scrollbar.
  381.      * @see Adjustable#getUnitIncrement
  382.      * @see #getUnitIncrement(int)
  383.      */
  384.     public int getUnitIncrement() {
  385.         return unitIncrement;
  386.     }
  387.  
  388.  
  389.     /**
  390.      * For backwards compatibility with java.awt.Scrollbar.
  391.      * @see Adjustable#getBlockIncrement
  392.      * @see #getBlockIncrement(int)
  393.      */
  394.     public int getBlockIncrement() {
  395.         return blockIncrement;
  396.     }
  397.  
  398.  
  399.     /**
  400.      * Returns the scrollbar's value.
  401.      * @return the model's value property
  402.      * @see #setValue
  403.      */
  404.     public int getValue() { 
  405.         return getModel().getValue(); 
  406.     }
  407.  
  408.  
  409.     /**
  410.      * Sets the scrollbar's value.  This method just forwards the value
  411.      * to the model.
  412.      *
  413.      * @see #getValue
  414.      * @see BoundedRangeModel#setValue
  415.      * @beaninfo
  416.      *   preferred: true
  417.      *       bound: true
  418.      * description: The scrollbar's current value.
  419.      */
  420.     public void setValue(int value) {
  421.         BoundedRangeModel m = getModel();
  422.         int oldValue = m.getValue();
  423.         m.setValue(value);
  424.  
  425.         if (accessibleContext != null) {
  426.             accessibleContext.firePropertyChange(
  427.                     AccessibleContext.ACCESSIBLE_VALUE_PROPERTY,
  428.                     new Integer(oldValue),
  429.                     new Integer(m.getValue()));
  430.         }
  431.     }
  432.  
  433.  
  434.     /**
  435.      * Returns the scrollbar's extent, aka its "visibleAmount".  In many 
  436.      * scrollbar look and feel implementations the size of the 
  437.      * scrollbar "knob" or "thumb" is proportional to the extent.
  438.      * 
  439.      * @return the value of the model's extent property
  440.      * @see #setVisibleAmount
  441.      */
  442.     public int getVisibleAmount() { 
  443.         return getModel().getExtent(); 
  444.     }
  445.  
  446.  
  447.     /**
  448.      * Set the model's extent property.
  449.      * 
  450.      * @see #getVisibleAmount
  451.      * @see BoundedRangeModel#setExtent
  452.      * @beaninfo
  453.      *   preferred: true
  454.      * description: The amount of the view that is currently visible.
  455.      */
  456.     public void setVisibleAmount(int extent) { 
  457.         getModel().setExtent(extent); 
  458.     }
  459.  
  460.  
  461.     /**
  462.      * Returns the minimum value supported by the scrollbar 
  463.      * (usually zero).
  464.      *
  465.      * @return the value of the model's minimum property
  466.      * @see #setMinimum
  467.      */
  468.     public int getMinimum() { 
  469.         return getModel().getMinimum(); 
  470.     }
  471.  
  472.  
  473.     /**
  474.      * Sets the model's minimum property.
  475.      *
  476.      * @see #getMinimum
  477.      * @see BoundedRangeModel#setMinimum
  478.      * @beaninfo
  479.      *   preferred: true
  480.      * description: The scrollbar's minimum value.
  481.      */
  482.     public void setMinimum(int minimum) { 
  483.         getModel().setMinimum(minimum); 
  484.     }
  485.  
  486.  
  487.     /**
  488.      * The maximum value of the scrollbar is maximum - extent.
  489.      *
  490.      * @return the value of the model's maximum property
  491.      * @see #setMaximum
  492.      */
  493.     public int getMaximum() { 
  494.         return getModel().getMaximum(); 
  495.     }
  496.  
  497.  
  498.     /**
  499.      * Sets the model's maximum property.  Note that the scrollbar's value
  500.      * can only be set to maximum - extent.
  501.      * 
  502.      * @see #getMaximum
  503.      * @see BoundedRangeModel#setMaximum
  504.      * @beaninfo
  505.      *   preferred: true
  506.      * description: The scrollbar's maximum value. 
  507.      */
  508.     public void setMaximum(int maximum) { 
  509.         getModel().setMaximum(maximum); 
  510.     }
  511.  
  512.  
  513.     /**
  514.      * True if the scrollbar knob is being dragged.
  515.      * 
  516.      * @return the value of the model's valueIsAdjusting property
  517.      * @see #setValueIsAdjusting
  518.      */
  519.     public boolean getValueIsAdjusting() { 
  520.         return getModel().getValueIsAdjusting(); 
  521.     }
  522.  
  523.  
  524.     /**
  525.      * Sets the model's valueIsAdjusting property.  Scrollbar look and
  526.      * feel implementations should set this property to true when 
  527.      * a knob drag begins, and to false when the drag ends.  The
  528.      * scrollbar model will not generate ChangeEvents while
  529.      * valueIsAdjusting is true.
  530.      * 
  531.      * @see #getValueIsAdjusting
  532.      * @see BoundedRangeModel#setValueIsAdjusting
  533.      * @beaninfo
  534.      *      expert: true
  535.      *       bound: true
  536.      * description: True if the scrollbar thumb is being dragged.
  537.      */
  538.     public void setValueIsAdjusting(boolean b) { 
  539.         BoundedRangeModel m = getModel();   
  540.         boolean oldValue = m.getValueIsAdjusting();
  541.         m.setValueIsAdjusting(b);
  542.    
  543.         if ((oldValue != b) && (accessibleContext != null)) {
  544.             accessibleContext.firePropertyChange(
  545.                     AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
  546.                     ((oldValue) ? AccessibleState.BUSY : null),
  547.                     ((b) ? AccessibleState.BUSY : null));
  548.         }
  549.     }
  550.  
  551.  
  552.     /**
  553.      * Sets the four BoundedRangeModel properties after forcing
  554.      * the arguments to obey the usual constraints:
  555.      * <pre>
  556.      * minimum <= value <= value+extent <= maximum
  557.      * </pre>
  558.      * <p>
  559.      * 
  560.      * @see BoundedRangeModel#setRangeProperties
  561.      * @see #setValue
  562.      * @see #setVisibleAmount
  563.      * @see #setMinimum
  564.      * @see #setMaximum
  565.      */
  566.     public void setValues(int newValue, int newExtent, int newMin, int newMax)    
  567.     {
  568.         BoundedRangeModel m = getModel();
  569.         int oldValue = m.getValue();
  570.         m.setRangeProperties(newValue, newExtent, newMin, newMax, m.getValueIsAdjusting());
  571.  
  572.         if (accessibleContext != null) {
  573.             accessibleContext.firePropertyChange(
  574.                     AccessibleContext.ACCESSIBLE_VALUE_PROPERTY,
  575.                     new Integer(oldValue),
  576.                     new Integer(m.getValue()));
  577.         }
  578.     }
  579.  
  580.  
  581.     /**
  582.      * Adds an AdjustmentListener.  Adjustment listeners are notified
  583.      * each time the scrollbar's model changes.  Adjustment events are 
  584.      * provided for backwards compatability with java.awt.Scrollbar.
  585.      * <p>
  586.      * Note that the AdjustmentEvents type property will always have a
  587.      * placeholder value of AdjustmentEvent.TRACK because all changes
  588.      * to a BoundedRangeModels value are considered equivalent.  To change
  589.      * the value of a BoundedRangeModel one just sets its value property,
  590.      * i.e. model.setValue(123).  No information about the origin of the
  591.      * change, e.g. it's a block decrement, is provided.  We don't try
  592.      * fabricate the origin of the change here.
  593.      *
  594.      * @param l the AdjustmentLister to add
  595.      * @see #removeAdjustmentListener
  596.      * @see BoundedRangeModel#addChangeListener
  597.      */
  598.     public void addAdjustmentListener(AdjustmentListener l)   {
  599.         listenerList.add(AdjustmentListener.class, l);
  600.     }
  601.  
  602.  
  603.     /**
  604.      * Removes an AdjustmentEvent listener.
  605.      *
  606.      * @param l the AdjustmentLister to remove
  607.      * @see #addAdjustmentListener
  608.      */
  609.     public void removeAdjustmentListener(AdjustmentListener l)  {
  610.         listenerList.remove(AdjustmentListener.class, l);
  611.     }
  612.  
  613.  
  614.     /*
  615.      * Notify listeners that the scrollbar's model has changed.
  616.      * 
  617.      * @see #addAdjustmentListener
  618.      * @see EventListenerList
  619.      */
  620.     protected void fireAdjustmentValueChanged(int id, int type, int value) {
  621.         Object[] listeners = listenerList.getListenerList();
  622.         AdjustmentEvent e = null;
  623.         for (int i = listeners.length - 2; i >= 0; i -= 2) {
  624.             if (listeners[i]==AdjustmentListener.class) {
  625.                 if (e == null) {
  626.                     e = new AdjustmentEvent(this, id, type, value);
  627.                 }
  628.                 ((AdjustmentListener)listeners[i+1]).adjustmentValueChanged(e);
  629.             }          
  630.         }
  631.     }   
  632.  
  633.  
  634.     /** 
  635.      * This class listens to ChangeEvents on the model and forwards 
  636.      * AdjustmentEvents for the sake of backwards compatibility. 
  637.      * Unfortunately there's no way to determine the proper
  638.      * type of the AdjustmentEvent as all updates to the model's
  639.      * value are considered equivalent. 
  640.      */
  641.     private class ModelListener implements ChangeListener, Serializable {
  642.         public void stateChanged(ChangeEvent e)   {
  643.             int id = AdjustmentEvent.ADJUSTMENT_VALUE_CHANGED;
  644.             int type = AdjustmentEvent.TRACK;
  645.             fireAdjustmentValueChanged(id, type, getValue());
  646.         }
  647.     }
  648.  
  649.     // PENDING(hmuller) - the next three methods should be removed
  650.  
  651.     /**
  652.      * The scrollbar is flexible along it's scrolling axis and 
  653.      * rigid along the other axis.
  654.      */
  655.     public Dimension getMinimumSize() {
  656.         Dimension pref = getPreferredSize();
  657.         if (orientation == VERTICAL) {
  658.             return new Dimension(pref.width, 5);
  659.         } else {
  660.             return new Dimension(5, pref.height);
  661.         }
  662.     }
  663.  
  664.     /**
  665.      * The scrollbar is flexible along it's scrolling axis and
  666.      * rigid along the other axis.
  667.      */
  668.     public Dimension getMaximumSize() {
  669.         Dimension pref = getPreferredSize();
  670.         if (getOrientation() == VERTICAL) {
  671.             return new Dimension(pref.width, Short.MAX_VALUE);
  672.         } else {
  673.             return new Dimension(Short.MAX_VALUE, pref.height);
  674.         }
  675.     }
  676.  
  677.     /**
  678.      * Enables the component so that the knob position can be changed.
  679.      * When the disabled, the knob position cannot be changed.
  680.      *
  681.      * @param b a boolean value, where true enables the component and
  682.      *          false disables it
  683.      */
  684.     public void setEnabled(boolean x)  {
  685.         super.setEnabled(x);
  686.         Component[] children = getComponents();
  687.         for(int i = 0; i < children.length; i++) {
  688.             children[i].setEnabled(x);
  689.         }
  690.     }
  691.  
  692.     /** 
  693.      * See readObject() and writeObject() in JComponent for more 
  694.      * information about serialization in Swing.
  695.      */
  696.     private void writeObject(ObjectOutputStream s) throws IOException {
  697.         s.defaultWriteObject();
  698.     if ((ui != null) && (getUIClassID().equals(uiClassID))) {
  699.         ui.installUI(this);
  700.     }
  701.     }
  702.  
  703.  
  704.     /**
  705.      * Returns a string representation of this JScrollBar. This method 
  706.      * is intended to be used only for debugging purposes, and the 
  707.      * content and format of the returned string may vary between      
  708.      * implementations. The returned string may be empty but may not 
  709.      * be <code>null</code>.
  710.      * <P>
  711.      * Overriding paramString() to provide information about the
  712.      * specific new aspects of the JFC components.
  713.      * 
  714.      * @return  a string representation of this JScrollBar.
  715.      */
  716.     protected String paramString() {
  717.     String orientationString = (orientation == HORIZONTAL ?
  718.                     "HORIZONTAL" : "VERTICAL");
  719.  
  720.     return super.paramString() +
  721.     ",blockIncrement=" + blockIncrement +
  722.     ",orientation=" + orientationString +
  723.     ",unitIncrement=" + unitIncrement;
  724.     }
  725.  
  726. /////////////////
  727. // Accessibility support
  728. ////////////////
  729.  
  730.     /**
  731.      * Get the AccessibleContext associated with this JComponent
  732.      *
  733.      * @return the AccessibleContext of this JComponent
  734.      */
  735.     public AccessibleContext getAccessibleContext() {
  736.         if (accessibleContext == null) {
  737.             accessibleContext = new AccessibleJScrollBar();
  738.         }
  739.         return accessibleContext;
  740.     }
  741.  
  742.     /**
  743.      * The class used to obtain the accessible role for this object.
  744.      * <p>
  745.      * <strong>Warning:</strong>
  746.      * Serialized objects of this class will not be compatible with
  747.      * future Swing releases.  The current serialization support is appropriate
  748.      * for short term storage or RMI between applications running the same
  749.      * version of Swing.  A future release of Swing will provide support for
  750.      * long term persistence.
  751.      */
  752.     protected class AccessibleJScrollBar extends AccessibleJComponent
  753.         implements AccessibleValue {
  754.  
  755.         /**
  756.          * Get the state set of this object.
  757.          *
  758.          * @return an instance of AccessibleState containing the current state 
  759.          * of the object
  760.          * @see AccessibleState
  761.          */
  762.         public AccessibleStateSet getAccessibleStateSet() {
  763.             AccessibleStateSet states = super.getAccessibleStateSet();
  764.             if (getValueIsAdjusting()) {
  765.                 states.add(AccessibleState.BUSY);
  766.             }
  767.             if (getOrientation() == VERTICAL) {
  768.                 states.add(AccessibleState.VERTICAL);
  769.             } else {
  770.                 states.add(AccessibleState.HORIZONTAL);
  771.             }
  772.             return states;
  773.         }
  774.  
  775.         /**
  776.          * Get the role of this object.
  777.          *
  778.          * @return an instance of AccessibleRole describing the role of the 
  779.          * object
  780.          */
  781.         public AccessibleRole getAccessibleRole() {
  782.             return AccessibleRole.SCROLL_BAR;
  783.         }
  784.  
  785.         /**
  786.          * Get the AccessibleValue associated with this object if one
  787.          * exists.  Otherwise return null.
  788.          */
  789.         public AccessibleValue getAccessibleValue() {
  790.             return this;
  791.         }
  792.  
  793.         /**
  794.          * Get the accessible value of this object.
  795.          *
  796.          * @return The current value of this object.
  797.          */
  798.         public Number getCurrentAccessibleValue() {
  799.             return new Integer(getValue());
  800.         }
  801.  
  802.         /**
  803.          * Set the value of this object as a Number.
  804.          *
  805.          * @return True if the value was set.
  806.          */
  807.         public boolean setCurrentAccessibleValue(Number n) {
  808.             if (n instanceof Integer) {
  809.                 setValue(n.intValue());
  810.                 return true;
  811.             } else {
  812.                 return false;
  813.             }
  814.         }
  815.  
  816.         /**
  817.          * Get the minimum accessible value of this object.
  818.          *
  819.          * @return The minimum value of this object.
  820.          */
  821.         public Number getMinimumAccessibleValue() {
  822.             return new Integer(getMinimum());
  823.         }
  824.  
  825.         /**
  826.          * Get the maximum accessible value of this object.
  827.          *
  828.          * @return The maximum value of this object.
  829.          */
  830.         public Number getMaximumAccessibleValue() {
  831.             return new Integer(getMaximum());
  832.         }
  833.  
  834.     } // AccessibleJScrollBar
  835. }
  836.